import csv
import yaml
from os.path import dirname, join, abspath

# 这里open的基路径是main.py
with open(join(dirname(str(abspath(__file__))),'init.yml'), 'r', encoding='utf-8') as f:
    init_config= yaml.load(f.read(), Loader=yaml.FullLoader)
def csv_read(row_index, col_index):
    human_init_csv_path = join(dirname(dirname(str(abspath(__file__)))),init_config['human_init_path'])
    try:
        with open(human_init_csv_path, 'r',encoding='utf-8-sig') as csvfile:
            csv_file = csv.reader(csvfile)
            csv_file_list = list(csv_file)
    except:
        print('human_init_path is not correct')
        return None

    num_row = len(csv_file_list)
    if row_index > num_row or row_index < 0:
        print('row_index is out of range')
        return None
    elif col_index > 4 or col_index < 0:
        print('col_index is out of range')
        return None
    else:
        data = csv_file_list[row_index][col_index]

    return data